Public Class CCreditNotes
    Inherits BOBase

    Private m_DA As CreditNotes
    Private m_state As CreditNotesDS

#Region "   Inherits Implementation"

    Public Sub New()
        Me.m_DA = New CreditNotes
        Me.m_state = New CreditNotesDS
    End Sub

    Public Overrides ReadOnly Property DA() As DABase
        Get
            If m_DA Is Nothing Then
                m_DA = New CreditNotes
            End If
            Return m_DA
        End Get
    End Property

    Public Overrides Sub Init()
        Dim Row As CreditNotesDS.CREDIT_NOTESRow
        Row = Me.m_state.CREDIT_NOTES.NewCREDIT_NOTESRow
        With Row
            .CUSTOMER_ID_FK = Nothing
            .NUMBER = String.Empty
            .DESCRIPTION = String.Empty
            .CREATED_DATE = Date.Now
            .VALUE_ = 0
            .SUPPLIER_CODE_ID_FK = 0
            .SetCREATED_BYNull()
            .SetUPDATED_BYNull()
            .SetUPDATED_DATENull()
        End With
        m_state.CREDIT_NOTES.AddCREDIT_NOTESRow(Row)

    End Sub

    Public Overrides Property ObjectState() As System.Data.DataSet
        Get
            Return m_state
        End Get
        Set(ByVal Value As System.Data.DataSet)
            Try
                m_state = CType(Value, CreditNotesDS)
            Catch ex As InvalidCastException
                Throw New ApplicationException("Invalid CREDIT NOTES Dataset!", ex)
            End Try
        End Set
    End Property
#End Region

#Region "   Data Properties"
    Private ReadOnly Property DataRow() As CreditNotesDS.CREDIT_NOTESRow
        Get
            Return CType(Me.Row, CreditNotesDS.CREDIT_NOTESRow)
        End Get
    End Property

    Public ReadOnly Property CnIdPk() As System.Int32
        Get
            Return Me.DataRow.CN_ID_PK
        End Get
    End Property

    Public Property CustomerIdFk() As System.Int32
        Get
            Return Me.DataRow.CUSTOMER_ID_FK
        End Get
        Set(ByVal Value As System.Int32)
            Me.DataRow.CUSTOMER_ID_FK = Value
        End Set
    End Property

    Public Property Number() As System.String
        Get
            Return Me.DataRow.NUMBER
        End Get
        Set(ByVal Value As System.String)
            Me.DataRow.NUMBER = Value
        End Set
    End Property

    Public Property Description() As System.String
        Get
            Return Me.DataRow.DESCRIPTION
        End Get
        Set(ByVal Value As System.String)
            Me.DataRow.DESCRIPTION = Value
        End Set
    End Property

    Public Property CreatedDate() As System.DateTime
        Get
            Return Me.DataRow.CREATED_DATE
        End Get
        Set(ByVal Value As System.DateTime)
            Me.DataRow.CREATED_DATE = Value
        End Set
    End Property

    Public Property Value() As System.Decimal
        Get
            Return Me.DataRow.VALUE_
        End Get
        Set(ByVal Value As System.Decimal)
            Me.DataRow.VALUE_ = Value
        End Set
    End Property

    Public Property CreatedBy() As System.Int32
        Get
            If Me.DataRow.IsCREATED_BYNull Then
                Return Nothing
            Else
                Return Me.DataRow.CREATED_BY
            End If
        End Get
        Set(ByVal Value As System.Int32)
            If Value = Nothing Then
                Me.DataRow.SetCREATED_BYNull()
            Else
                Me.DataRow.CREATED_BY = Value
            End If
        End Set
    End Property

    Public Property UpdatedBy() As System.Int32
        Get
            If Me.DataRow.IsUPDATED_BYNull Then
                Return Nothing
            Else
                Return Me.DataRow.UPDATED_BY
            End If
        End Get
        Set(ByVal Value As System.Int32)
            If Value = Nothing Then
                Me.DataRow.SetUPDATED_BYNull()
            Else
                Me.DataRow.UPDATED_BY = Value
            End If
        End Set
    End Property

    Public Property UpdatedDate() As System.DateTime
        Get
            If Me.DataRow.IsUPDATED_DATENull Then
                Return Nothing
            Else
                Return Me.DataRow.UPDATED_DATE
            End If
        End Get
        Set(ByVal Value As System.DateTime)
            If Value = Nothing Then
                Me.DataRow.SetUPDATED_DATENull()
            Else
                Me.DataRow.UPDATED_DATE = Value
            End If
        End Set
    End Property

    Public Property SupplierCodeIdFk() As System.Int32
        Get
            Return Me.DataRow.SUPPLIER_CODE_ID_FK            
        End Get
        Set(ByVal Value As System.Int32)
            Me.DataRow.SUPPLIER_CODE_ID_FK = Value
        End Set
    End Property

#End Region


    Public Shared Function GetCreditNotesList(ByVal CustomerID As Int32) As DataTable
        Dim ds As New DataSet
        ds = DataHelper.ExecuteDataSet2("GetCreditNotesList", CustomerID)
        Return ds.Tables(0)
    End Function

    Public Function GetCreditNotesListBySupplier(ByVal customerID As Integer, ByVal supplierID As Integer) As DataSet
        Return m_DA.GetCreditNotesListBySupplier(customerID, supplierID)
    End Function
End Class
